import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from "./store/index";

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import * as echarts from 'echarts';
Vue.use(ElementUI)

//引入 axios
import axios from 'axios'


//必须要先加载拦截器之后再把axios交给vue
axios.interceptors.request.use((config) => {
    let token = sessionStorage.getItem("token");
    if (token) {
        config.headers['token'] = token;
    }
    return config;
})

axios.interceptors.response.use((config) => {
    let data = config.data;
    console.log(config.data)
    //把data字符串转成 json对象
    //let parse = JSON.parse(data);
    if (data.code == 403) {
        vueApp.$message({
            type: 'error',
            message: data.msg,
            duration: 1000
        });
        vueApp.$router.push("/");
    }
    return config;
})

//设置默认地址
axios.defaults.baseURL = "http://localhost:8088"
//把axios对象 绑定到Vue对象的原型上
Vue.prototype.$axios = axios;

import './assets/css/global.css'

Vue.config.productionTip = false

let vueApp = new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')


